package it.trekker.adapter;

import it.trekker.R;
import it.trekker.dataexchange.PoiRealTimeInfo;
import it.trekker.statistics.PoiDistanceStatistics;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class PoiAdapter extends ArrayAdapter<PoiRealTimeInfo> {

	private int resource;
	private PoiDistanceStatistics poiDistanceStat;
	
	public PoiAdapter(Context context, int resource, List<PoiRealTimeInfo> objects, PoiDistanceStatistics poiDistanceStat) {
		super(context, resource, objects);
		
		this.resource = resource;
		this.poiDistanceStat = poiDistanceStat;
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		RelativeLayout layout;
		PoiRealTimeInfo poi = getItem(position);
		
		if(convertView == null) {
			layout = new RelativeLayout(getContext());
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			inflater.inflate(resource, layout, true);
		}
		else {
			layout = (RelativeLayout) convertView;
		}
		
		TextView poiName_tv = (TextView) layout.findViewById(R.id.poi_name);
		TextView poiDistance_tv = (TextView) layout.findViewById(R.id.poi_distance);
		TextView poiExtimatedTime_tv = (TextView) layout.findViewById(R.id.poi_extimatedtime);
		TextView poiLocation_tv = (TextView) layout.findViewById(R.id.poi_location);
		
		poiName_tv.setText(poi.getPoi().getFriendlyName());
		String locationStr = String.format("%f, %f", poi.getPoi().getLocation().getLatitude(), poi.getPoi().getLocation().getLongitude());
		poiLocation_tv.setText(locationStr);
		String distanceStr = String.format("%.3f Km", poi.getDistanceToGoal()/1000f);
		poiDistance_tv.setText(distanceStr);
		poiExtimatedTime_tv.setText("et");
		
		return layout;
	}
}
